<?php
namespace app\storeapi\controller\resources;

use app\storeapi\controller\Controller;
use app\storeapi\model\resources\Resources as ResourcesModel;

class Resources extends Controller
{
    /**
     * 资源列表
     * @param string $nickName 昵称
     * @param int $gender 性别
     * @param int $grade 会员等级
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $param = $this->postData();
        $model = new ResourcesModel;
        $list = $model->getList($param);
        return $this->renderSuccess($list);

    }


    /**
     * 课件详情
     * @param $resources_id
     * @return array|mixed
     * @throws \think\exception\DbException
     */
    public function detail()
    {
        $param = $this->postData();
        $model = new ResourcesModel;
        $data = $model->info($param);
        if(!$data) return $this->renderError('该资源不存在，请刷新重试');
        $data['resources_content'] = htmlspecialchars_decode($data['resources_content']);
        $data['down_url'] = $data['file_url']."/".$data['file_name'];
        return $this->renderSuccess($data);
    }

    /**
     * 课件详情
     * @param $resources_id
     * @return array|mixed
     * @throws \think\exception\DbException
     */
    public function down()
    {
        $param = $this->postData();
        $model = new ResourcesModel;
        $data = $model->down($param);
        return $this->renderSuccess([],'成功');
    }


}